/*
 * CNSATMSMARTView.java
 */

package cnsatmsmart;

import cnsatmsmart.automation.mmi.controller.Buffer.Asterix21DataList;
import cnsatmsmart.automation.mmi.controller.Buffer.BufferThread;
import cnsatmsmart.automation.mmi.controller.Buffer.FlightList;
import cnsatmsmart.automation.mmi.controller.Buffer.FlightPlanList;
import cnsatmsmart.automation.mmi.controller.Buffer.FlightPlanThread;
import cnsatmsmart.automation.mmi.controller.Buffer.OffCheckThread;
import cnsatmsmart.automation.mmi.controller.IO.ImageDriver;
import cnsatmsmart.automation.mmi.controller.IO.PDFWriter;
import cnsatmsmart.automation.mmi.controller.IO.Painter;
import cnsatmsmart.automation.mmi.controller.client.ClientMulticastThread;
import cnsatmsmart.automation.mmi.controller.client.ClientThread;
import cnsatmsmart.automation.mmi.controller.event.NavMouseMode3;
import cnsatmsmart.automation.mmi.controller.event.OverviewMouseMode;
import cnsatmsmart.automation.mmi.controller.event.ZoomMouseMode;
import cnsatmsmart.automation.mmi.helper.utilities.GlobalEnvVars;
import cnsatmsmart.automation.mmi.model.OMMapPanel;
import cnsatmsmart.automation.mmi.view.dialogs.connectionSetting;
import cnsatmsmart.automation.mmi.view.dialogs.databaseSettings;
import cnsatmsmart.automation.mmi.view.dialogs.flightSetting;
import cnsatmsmart.automation.mmi.view.dialogs.listFlightView;
import cnsatmsmart.automation.mmi.view.dialogs.radarSettings;
import cnsatmsmart.automation.mmi.view.layers.RadarLayer;
import com.bbn.openmap.LatLonPoint;
import com.bbn.openmap.event.PanMouseMode;
import com.bbn.openmap.event.SelectMouseMode;
import com.itextpdf.text.DocumentException;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.GraphicsEnvironment;
import java.awt.Image;
import java.awt.Rectangle;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.util.EventObject;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ButtonGroup;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.JTabbedPane;
import javax.swing.filechooser.FileNameExtensionFilter;

/**
 * The application's main frame.
 */
public class CNSATMSMARTView extends FrameView {

    /* atribut - atribut yang dimiliki oleh kelas CNSATMSMARTView */
        private JTabbedPane tabPanel;
        private final OMMapPanel mapPanel;                              //panel map untuk panel utama
        private final OMMapPanel mapPanel2;                             //panel map untuk panel pada zoomAreaWindow
        private FlightPlanList flightPlanList = new FlightPlanList();
        private boolean isConnect = false;                              //jika tombol connect dipilih
        private boolean isRecord = false;                               //jika tombol record dipilih

        private ClientThread ct;
        private BufferThread BuffThread;
        private OffCheckThread  offcheck;
        private Painter painter;
        private listFlightView FlightTable;
        private ClientMulticastThread CMT;
        private FlightPlanThread FPT;

        private Asterix21DataList Ax21DataList;
        private FlightList FlightDat;
        private Thread threadProcess;
        private Thread ThreadBuff;
        private Thread threadOC;
        private Thread threadPT;
        private Thread threadFPT;

        private String ScreenTitle = "ADSB Virtual Radar Display 2.0";

        private JDialog ZoomAreaWindow = new JDialog(); //untuk tampilan ZoomArea
        private boolean isNewWindow = true;

        private JSplitPane splitHorPane, splitVerPane;

    /**
     * Constructor - user defined constructor, no default constructor
     * @param app
     */
        public CNSATMSMARTView(SingleFrameApplication app) {
            super(app);

            initComponents();

            this.getApplication().addExitListener(new ExitHandler());

            Image frameIcon = GlobalEnvVars.kit.getImage(getClass().getResource("/cnsatmsmart/resources/"+GlobalEnvVars.icon));
            getFrame().setIconImage(frameIcon);
            getFrame().setTitle(ScreenTitle);

            if (!InitIfFileExits())
            {
                GlobalEnvVars.port = 6789;
                GlobalEnvVars.ipServer = "127.0.0.1";
                GlobalEnvVars.isUnicast = true;
            }

            mapPanel = new OMMapPanel(ScreenTitle);
            mapPanel.addControlLayer();
            mapPanel2 = new OMMapPanel(ScreenTitle);
            mapPanel2.setBackground(new Color(0,70,70));
            statusPanel.setVisible(false);

            this.tabPanel = new JTabbedPane();
            splitHorPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,mapPanel,bottomPanel);
            splitVerPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, splitHorPane, sidePanel);
            splitVerPane.setEnabled(false);
            splitHorPane.setEnabled(false);
            splitVerPane.setDividerLocation(GlobalEnvVars.screenWidth-100);
            splitHorPane.setDividerLocation(GlobalEnvVars.screenHeight);
            tabPanel.addTab("Map", splitVerPane);
            setComponent(tabPanel);

            zoomAreaMenu.setEnabled(false);
            //<editor-fold defaultstate="colapsed" desc="zoomAreaWindow">
            this.ZoomAreaWindow.setIconImage(frameIcon);
            this.ZoomAreaWindow.setTitle("Zoom Area");
            this.ZoomAreaWindow.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
            this.ZoomAreaWindow.setSize((int)(GlobalEnvVars.screenWidth/3), (int)(GlobalEnvVars.screenHeight/2));
            this.ZoomAreaWindow.setResizable(false);
            this.ZoomAreaWindow.setLocation(GlobalEnvVars.screenWidth-ZoomAreaWindow.getWidth(), 0);
            this.ZoomAreaWindow.setAlwaysOnTop(true);
            //</editor-fold>
            //<editor-fold defaultstate="collapsed" desc="Toolbar">
            this.setToolBar(mainToolbar);
            buttonGroup = new ButtonGroup();
            buttonGroup.add(tbSelect);
            buttonGroup.add(tbPan);
            buttonGroup.add(tbZoom);
            buttonGroup.add(tbZoomArea);
            buttonGroup.add(tbTapZoom);
            tbSelect.setSelected(true);

            cbZoom.setSelectedIndex(2);
            cbZoom.setMaximumSize(new Dimension(60,20));

            tbDistance.setEnabled(false);
            tbSelectedTrails.setEnabled(false);
            tbShowAllTrails.setEnabled(false);
            btnRecord.setEnabled(false);
            tbZoomArea.setEnabled(false);
            tbBearingAndDistance.setEnabled(false);
            tbAllFlightPlan.setEnabled(false);
            tbSelectedFlightPlan.setEnabled(false);
            //</editor-fold>

            //<editor-fold defaultstate="collapsed" desc="status bar">
            // status bar initialization - message timeout, idle icon and busy animation, etc
            ResourceMap resourceMap = getResourceMap();
            int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
            messageTimer = new Timer(messageTimeout, new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    statusMessageLabel.setText("");
                }
            });
            messageTimer.setRepeats(false);
            int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
            for (int i = 0; i < busyIcons.length; i++) {
                busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
            }
            busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                    statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
                }
            });
            idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
            statusAnimationLabel.setIcon(idleIcon);
            progressBar.setVisible(false);

            // connecting action tasks to status bar via TaskMonitor
            TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
            taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
                public void propertyChange(java.beans.PropertyChangeEvent evt) {
                    String propertyName = evt.getPropertyName();
                    if ("started".equals(propertyName)) {
                        if (!busyIconTimer.isRunning()) {
                            statusAnimationLabel.setIcon(busyIcons[0]);
                            busyIconIndex = 0;
                            busyIconTimer.start();
                        }
                        progressBar.setVisible(true);
                        progressBar.setIndeterminate(true);
                    } else if ("done".equals(propertyName)) {
                        busyIconTimer.stop();
                        statusAnimationLabel.setIcon(idleIcon);
                        progressBar.setVisible(false);
                        progressBar.setValue(0);
                    } else if ("message".equals(propertyName)) {
                        String text = (String)(evt.getNewValue());
                        statusMessageLabel.setText((text == null) ? "" : text);
                        messageTimer.restart();
                    } else if ("progress".equals(propertyName)) {
                        int value = (Integer)(evt.getNewValue());
                        progressBar.setVisible(true);
                        progressBar.setIndeterminate(false);
                        progressBar.setValue(value);
                    }
                }
            });
            //</editor-fold>

            JFrame.setDefaultLookAndFeelDecorated(false);

            Rectangle bounds = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
            getFrame().setMinimumSize(new Dimension(bounds.width, bounds.height));
            getFrame().setResizable(false);
            getFrame().setLocationRelativeTo(null);
        }

    /* method - method lain yang dimiliki oleh kelas CNSATMSMARTView */
        public void updateLayer (int ID) {
            switch (ID)
            {
                case databaseSettings.AIRPORTS:
                {
                    mapPanel.updateAirportLayer();
                    mapPanel2.updateAirportLayer();
                    mapPanel.updateAirwaysLayer();
                    mapPanel2.updateAirwaysLayer();
                    break;
                }
                case databaseSettings.FIXES:
                {
                    mapPanel.updateFixesLayer(true, false);
                    mapPanel2.updateFixesLayer(true, false);
                    mapPanel.updateAirwaysLayer();
                    mapPanel2.updateAirwaysLayer();
                    break;
                }
                case databaseSettings.NAVAIDS:
                {
                    mapPanel.updateFixesLayer(false, true);
                    mapPanel2.updateFixesLayer(false, true);
                    mapPanel.updateAirwaysLayer();
                    mapPanel2.updateAirwaysLayer();
                    break;
                }
                case databaseSettings.AIRWAYS:
                {
                    mapPanel.updateAirwaysLayer();
                    mapPanel2.updateAirwaysLayer();
                    break;
                }
                case databaseSettings.FLIGHT_PLAN:
                {
                    this.flightPlanList.updateFlightPlan();
                    break;
                }
                default:
                    break;
            }
        }

        class ExitHandler implements org.jdesktop.application.Application.ExitListener
        {
            public boolean canExit(EventObject e) {
                if (FlightTable != null && FlightTable.isVisible()) FlightTable.setAlwaysOnTop(false);
                if (ZoomAreaWindow != null && ZoomAreaWindow.isVisible()) ZoomAreaWindow.setAlwaysOnTop(false);

                int reply = JOptionPane.showConfirmDialog(null, "Do you really want to exit?", "Confirm Exit", JOptionPane.YES_NO_OPTION);
                if (reply == JOptionPane.YES_OPTION){
                    if (isConnect){
                        try {
                            //Jika masih ada koneksi antara client/receiver dan server/sender, maka ditutup terlebih dahulu
                            Disconnect(true);
                        } catch (InterruptedException ex) {
                            Logger.getLogger(CNSATMSMARTView.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (IOException ex) {
                            Logger.getLogger(CNSATMSMARTView.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    }
                    return true;
                }else{
                    if (FlightTable.isVisible()) FlightTable.setAlwaysOnTop(true);
                    if (ZoomAreaWindow.isVisible()) ZoomAreaWindow.setAlwaysOnTop(true);
                    return false;
                }
            }
            public void willExit(EventObject e)
            {
            }
        }

        private boolean InitIfFileExits()
        {
            boolean fileExist = false;
            File f = new File ("conn_rec.txt");
            if (f.exists())
            {
                fileExist = true;
                readFromFile("conn_rec.txt");
            }
            return fileExist;
        }

        /**
         * Reads text from a file line by line
         */
        private void readFromFile(String filename) {
            BufferedReader bufferedReader = null;
            try {
                //Construct the BufferedReader object
                bufferedReader = new BufferedReader(new FileReader(filename));

                String line = null;
                int i = 0;

                while ((line = bufferedReader.readLine()) != null) {
                    if (i == 0)
                    {
                        if (line.equals("NULL")) GlobalEnvVars.ipServer = null ;
                        GlobalEnvVars.ipServer = line;
                    }
                    else if (i == 1)
                    {
                        if (line.equals("NULL")) GlobalEnvVars.port = 0;
                        else GlobalEnvVars.port = Integer.parseInt(line);
                    }
                    else if (i == 2)
                    {
                        if (line.equals("NULL")) GlobalEnvVars.BindInterface = null;
                        else GlobalEnvVars.BindInterface = line;
                    }
                    else if (i == 3)
                    {
                        if (line.equals("UNICAST"))
                        {
                            GlobalEnvVars.isUnicast = true;
                        }
                        else
                        {
                            GlobalEnvVars.isUnicast = false;
                        }
                    }
                    i++;
                }

            } catch (FileNotFoundException ex) {
                ex.printStackTrace();
            } catch (IOException ex) {
                ex.printStackTrace();
            } finally {
                //Close the BufferedReader
                try {
                    if (bufferedReader != null)
                        bufferedReader.close();
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            }
        }

        private static String getExtension(File f)
        {
                String ext = null;
                String s = f.getName();
                int i = s.lastIndexOf('.');

                if (i > 0 &&  i < s.length() - 1) {
                    ext = s.substring(i+1).toLowerCase();
                }
                return ext;
            }

        /**
         * menghitung persen yang dipilih dari cbZoom dan mengubah skala peta
         * @param persen angka yang tertera pada cbZoom
         */
        private void changeScale(float persen)
        {
            float temp = GlobalEnvVars.maxScale-(persen/100f*4975000f);
            this.mapPanel.setCurrentScale(temp,cbZoom);
        }

        /**
         * mem-validasi masukan pengguna dan mengubah latitude dan longitude pusat radar
         */
        public void updateRadarCenter()
        {
            RadarLayer radar = mapPanel.getRadarLayer();
            LatLonPoint prevRadarCenter = radar.getCenter();

            String[] latitude = GlobalEnvVars.latRadar;
            String[] longitude = GlobalEnvVars.lonRadar;

            float radarLatitude = 0.0f;
            float radarLongitude = 0.0f;
            try{
                int latDeg = Integer.parseInt(latitude[0]);
                int latMin = Integer.parseInt(latitude[1]);
                float latSec = Float.parseFloat(latitude[2]);
                int latSign = latitude[3].charAt(0) == 'N' ? 1 : -1;
                radarLatitude = latSign * (latDeg + (latMin / 60.0f) + (latSec / 3600.0f));

                int lonDeg = Integer.parseInt(longitude[0]);
                int lonMin = Integer.parseInt(longitude[1]);
                float lonSec = Float.parseFloat(longitude[2]);
                int lonSign = longitude[3].charAt(0) == 'E' ? 1 : -1;
                radarLongitude = lonSign * (lonDeg + (lonMin / 60.0f) + (lonSec / 3600.0f));
            }catch(NumberFormatException e){
                radarLatitude = 0.0f;
                radarLongitude = 0.0f;
            }catch(Exception exp){
                radarLatitude = 0.0f;
                radarLongitude = 0.0f;
            }

            if (radarLatitude == 0.0f && radarLongitude == 0.0f)
            {
                radarLatitude = prevRadarCenter.getLatitude();
                radarLongitude = prevRadarCenter.getLongitude();
            }

            radar.setCenter(radarLatitude, radarLongitude);
        }

        private void updateShowAll()
        {
            if (mapMenuItem.isSelected() && radarMenuItem.isSelected() && graticuleMenuItem.isSelected()
                    && fixesMenuItem.isSelected() && airportsMenuItem.isSelected() && airwaysMenuItem.isSelected())
                {showAllMenuItem.setSelected(true);}
        }

        public void Disconnect(boolean isDisconnect) throws InterruptedException, IOException
        {
            mapPanel.removeFlightLayer();
            mapPanel2.removeFlightLayer();

            if (elevationViewMenuItem.isSelected()) {
                mapPanel.setUnBenyengScale(mapPanel.getCurrentScale(), cbZoom);
            }
            elevationViewMenuItem.setSelected(elevationViewMenuItem.isSelected() ? !elevationViewMenuItem.isSelected() : elevationViewMenuItem.isSelected());
            splitHorPane.setDividerLocation(GlobalEnvVars.kit.getScreenSize().height - (elevationViewMenuItem.isSelected() ? GlobalEnvVars.chartHeight : 0));

            if (isDisconnect)
            {
                if (ct != null){
                    ct.Close();
                    threadProcess.join();
                }
                if (CMT != null){
                    //thread client multicast tidak akan ditunggu sampai proses selesai(join), karena akan terjadi deadlock
                    CMT.Close();
                }
                if (BuffThread != null){
                    BuffThread.Exit();
                    ThreadBuff.join();
                }
                if (offcheck != null){
                    offcheck.Exit();
                    threadOC.join();
                }
                if (painter != null){
                    painter.Exit();
                    threadPT.join();
                }
                if (FPT !=  null){
                    FPT.Exit();
                    threadFPT.join();
                }
                
                ct = null;
                CMT = null;
                BuffThread = null;
                offcheck = null;
                painter = null;
                FPT = null;

                threadProcess = null;
                ThreadBuff = null;
                threadOC = null;
                threadPT = null;
                threadFPT = null;
            }

            btnConnect.setText("Connect");
            btnConnect.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cnsatmsmart/resources/connect-icon.png")));
            isConnect = false;

            ZoomAreaWindow.setVisible(false);
            if (tabPanel.indexOfTab("Zoom Area") != -1)
            {
                tabPanel.remove(1);
            }

            this.tabPanel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));

            FlightTable.setVisible(false);
            flightListMenuItem.setEnabled(false);
            elevationViewMenuItem.setEnabled(false);
            tbDistance.setEnabled(false);
            tbSelectedTrails.setEnabled(false);
            tbShowAllTrails.setEnabled(false);
            btnRecord.setEnabled(false);
            tbZoomArea.setEnabled(false);
            tbBearingAndDistance.setEnabled(false);
            zoomAreaMenu.setEnabled(false);
            tbAllFlightPlan.setEnabled(false);
            tbSelectedFlightPlan.setEnabled(false);
        }

        public void CloseTopDialog(){
            if (FlightTable != null){
                if (FlightTable.isVisible()) FlightTable.setAlwaysOnTop(false);
            }
            if (ZoomAreaWindow != null){
                if (ZoomAreaWindow.isVisible()) ZoomAreaWindow.setAlwaysOnTop(false);
            }
        }

        public void ShowTopDialog(){
            if (FlightTable != null){
                if (FlightTable.isVisible()) FlightTable.setAlwaysOnTop(true);
            }
            if (ZoomAreaWindow != null){
                if (ZoomAreaWindow.isVisible()) ZoomAreaWindow.setAlwaysOnTop(true);
            }
        }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        copyToClipboard = new javax.swing.JMenuItem();
        saveAsJPGMenuItem = new javax.swing.JMenuItem();
        printMenu = new javax.swing.JMenu();
        aircraftListMenuItem = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        viewMenu = new javax.swing.JMenu();
        zoomAreaMenu = new javax.swing.JMenu();
        otherWindowMenuItem = new javax.swing.JRadioButtonMenuItem();
        tabWindowMenuItem = new javax.swing.JRadioButtonMenuItem();
        layersMenu = new javax.swing.JMenu();
        mapMenuItem = new javax.swing.JCheckBoxMenuItem();
        graticuleMenuItem = new javax.swing.JCheckBoxMenuItem();
        radarMenuItem = new javax.swing.JCheckBoxMenuItem();
        fixesMenuItem = new javax.swing.JCheckBoxMenuItem();
        airwaysMenuItem = new javax.swing.JCheckBoxMenuItem();
        airportsMenuItem = new javax.swing.JCheckBoxMenuItem();
        jSeparator2 = new javax.swing.JPopupMenu.Separator();
        showAllMenuItem = new javax.swing.JCheckBoxMenuItem();
        optionsMenu = new javax.swing.JMenu();
        radarSettingMenuItem = new javax.swing.JMenuItem();
        connectionMenuItem = new javax.swing.JMenuItem();
        flightOptionsMenuItem = new javax.swing.JMenuItem();
        windowMenu = new javax.swing.JMenu();
        flightListMenuItem = new javax.swing.JMenuItem();
        elevationViewMenuItem = new javax.swing.JMenuItem();
        databaseMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        showPdfMenuItem = new javax.swing.JMenuItem();
        websiteMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();
        mainToolbar = new javax.swing.JToolBar();
        btnConnect = new javax.swing.JButton();
        jSeparator3 = new javax.swing.JToolBar.Separator();
        tbSelect = new javax.swing.JToggleButton();
        tbPan = new javax.swing.JToggleButton();
        tbZoom = new javax.swing.JToggleButton();
        tbZoomArea = new javax.swing.JToggleButton();
        tbTapZoom = new javax.swing.JToggleButton();
        jSeparator4 = new javax.swing.JToolBar.Separator();
        btnZoomIn = new javax.swing.JButton();
        btnZoomOut = new javax.swing.JButton();
        btnFit = new javax.swing.JButton();
        cbZoom = new javax.swing.JComboBox();
        jSeparator5 = new javax.swing.JToolBar.Separator();
        tbShowAllTrails = new javax.swing.JToggleButton();
        tbSelectedTrails = new javax.swing.JToggleButton();
        tbDistance = new javax.swing.JToggleButton();
        tbBearingAndDistance = new javax.swing.JToggleButton();
        jSeparator6 = new javax.swing.JToolBar.Separator();
        tbAllFlightPlan = new javax.swing.JToggleButton();
        tbSelectedFlightPlan = new javax.swing.JToggleButton();
        jSeparator7 = new javax.swing.JToolBar.Separator();
        btnRecord = new javax.swing.JButton();

        mainPanel.setName("mainPanel"); // NOI18N

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 254, Short.MAX_VALUE)
        );

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setMnemonic('F');
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(cnsatmsmart.CNSATMSMARTApp.class).getContext().getResourceMap(CNSATMSMARTView.class);
        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        copyToClipboard.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_MASK));
        copyToClipboard.setText(resourceMap.getString("copyToClipboard.text")); // NOI18N
        copyToClipboard.setName("copyToClipboard"); // NOI18N
        copyToClipboard.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                copyToClipboardActionPerformed(evt);
            }
        });
        fileMenu.add(copyToClipboard);

        saveAsJPGMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        saveAsJPGMenuItem.setText(resourceMap.getString("saveAsJPGMenuItem.text")); // NOI18N
        saveAsJPGMenuItem.setName("saveAsJPGMenuItem"); // NOI18N
        saveAsJPGMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveAsJPGMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(saveAsJPGMenuItem);

        printMenu.setText(resourceMap.getString("printMenu.text")); // NOI18N
        printMenu.setName("printMenu"); // NOI18N

        aircraftListMenuItem.setText(resourceMap.getString("aircraftListMenuItem.text")); // NOI18N
        aircraftListMenuItem.setName("aircraftListMenuItem"); // NOI18N
        aircraftListMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aircraftListMenuItemActionPerformed(evt);
            }
        });
        printMenu.add(aircraftListMenuItem);

        fileMenu.add(printMenu);

        jSeparator1.setName("jSeparator1"); // NOI18N
        fileMenu.add(jSeparator1);

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(cnsatmsmart.CNSATMSMARTApp.class).getContext().getActionMap(CNSATMSMARTView.class, this);
        exitMenuItem.setAction(actionMap.get("exitMenuItemActionPerformed")); // NOI18N
        exitMenuItem.setText(resourceMap.getString("exitMenuItem.text")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        viewMenu.setMnemonic('V');
        viewMenu.setText(resourceMap.getString("viewMenu.text")); // NOI18N
        viewMenu.setName("viewMenu"); // NOI18N

        zoomAreaMenu.setText(resourceMap.getString("zoomAreaMenu.text")); // NOI18N
        zoomAreaMenu.setName("zoomAreaMenu"); // NOI18N

        otherWindowMenuItem.setSelected(true);
        otherWindowMenuItem.setText(resourceMap.getString("otherWindowMenuItem.text")); // NOI18N
        otherWindowMenuItem.setName("otherWindowMenuItem"); // NOI18N
        otherWindowMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                otherWindowMenuItemActionPerformed(evt);
            }
        });
        zoomAreaMenu.add(otherWindowMenuItem);

        tabWindowMenuItem.setSelected(true);
        tabWindowMenuItem.setText(resourceMap.getString("tabWindowMenuItem.text")); // NOI18N
        tabWindowMenuItem.setName("tabWindowMenuItem"); // NOI18N
        tabWindowMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tabWindowMenuItemActionPerformed(evt);
            }
        });
        zoomAreaMenu.add(tabWindowMenuItem);

        viewMenu.add(zoomAreaMenu);

        menuBar.add(viewMenu);

        layersMenu.setMnemonic('L');
        layersMenu.setText(resourceMap.getString("layersMenu.text")); // NOI18N
        layersMenu.setName("layersMenu"); // NOI18N

        mapMenuItem.setSelected(true);
        mapMenuItem.setText(resourceMap.getString("mapMenuItem.text")); // NOI18N
        mapMenuItem.setName("mapMenuItem"); // NOI18N
        mapMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mapMenuItemActionPerformed(evt);
            }
        });
        layersMenu.add(mapMenuItem);

        graticuleMenuItem.setSelected(true);
        graticuleMenuItem.setText(resourceMap.getString("graticuleMenuItem.text")); // NOI18N
        graticuleMenuItem.setName("graticuleMenuItem"); // NOI18N
        graticuleMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                graticuleMenuItemActionPerformed(evt);
            }
        });
        layersMenu.add(graticuleMenuItem);

        radarMenuItem.setSelected(true);
        radarMenuItem.setText(resourceMap.getString("radarMenuItem.text")); // NOI18N
        radarMenuItem.setName("radarMenuItem"); // NOI18N
        radarMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                radarMenuItemActionPerformed(evt);
            }
        });
        layersMenu.add(radarMenuItem);

        fixesMenuItem.setSelected(true);
        fixesMenuItem.setText(resourceMap.getString("fixesMenuItem.text")); // NOI18N
        fixesMenuItem.setName("fixesMenuItem"); // NOI18N
        fixesMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fixesMenuItemActionPerformed(evt);
            }
        });
        layersMenu.add(fixesMenuItem);

        airwaysMenuItem.setSelected(true);
        airwaysMenuItem.setText(resourceMap.getString("airwaysMenuItem.text")); // NOI18N
        airwaysMenuItem.setName("airwaysMenuItem"); // NOI18N
        airwaysMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                airwaysMenuItemActionPerformed(evt);
            }
        });
        layersMenu.add(airwaysMenuItem);

        airportsMenuItem.setSelected(true);
        airportsMenuItem.setText(resourceMap.getString("airportsMenuItem.text")); // NOI18N
        airportsMenuItem.setName("airportsMenuItem"); // NOI18N
        airportsMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                airportsMenuItemActionPerformed(evt);
            }
        });
        layersMenu.add(airportsMenuItem);

        jSeparator2.setName("jSeparator2"); // NOI18N
        layersMenu.add(jSeparator2);

        showAllMenuItem.setSelected(true);
        showAllMenuItem.setText(resourceMap.getString("showAllMenuItem.text")); // NOI18N
        showAllMenuItem.setName("showAllMenuItem"); // NOI18N
        showAllMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                showAllMenuItemActionPerformed(evt);
            }
        });
        layersMenu.add(showAllMenuItem);

        menuBar.add(layersMenu);

        optionsMenu.setMnemonic('O');
        optionsMenu.setText(resourceMap.getString("optionsMenu.text")); // NOI18N
        optionsMenu.setName("optionsMenu"); // NOI18N

        radarSettingMenuItem.setText(resourceMap.getString("radarSettingMenuItem.text")); // NOI18N
        radarSettingMenuItem.setName("radarSettingMenuItem"); // NOI18N
        radarSettingMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                radarSettingMenuItemActionPerformed(evt);
            }
        });
        optionsMenu.add(radarSettingMenuItem);

        connectionMenuItem.setText(resourceMap.getString("connectionMenuItem.text")); // NOI18N
        connectionMenuItem.setName("connectionMenuItem"); // NOI18N
        connectionMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                connectionMenuItemActionPerformed(evt);
            }
        });
        optionsMenu.add(connectionMenuItem);

        flightOptionsMenuItem.setText(resourceMap.getString("flightOptionsMenuItem.text")); // NOI18N
        flightOptionsMenuItem.setName("flightOptionsMenuItem"); // NOI18N
        flightOptionsMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                flightOptionsMenuItemActionPerformed(evt);
            }
        });
        optionsMenu.add(flightOptionsMenuItem);

        menuBar.add(optionsMenu);

        windowMenu.setMnemonic('W');
        windowMenu.setText(resourceMap.getString("windowMenu.text")); // NOI18N
        windowMenu.setName("windowMenu"); // NOI18N

        flightListMenuItem.setText(resourceMap.getString("flightListMenuItem.text")); // NOI18N
        flightListMenuItem.setEnabled(false);
        flightListMenuItem.setName("flightListMenuItem"); // NOI18N
        flightListMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                flightListMenuItemActionPerformed(evt);
            }
        });
        windowMenu.add(flightListMenuItem);

        elevationViewMenuItem.setText(resourceMap.getString("elevationViewMenuItem.text")); // NOI18N
        elevationViewMenuItem.setEnabled(false);
        elevationViewMenuItem.setName("elevationViewMenuItem"); // NOI18N
        elevationViewMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                elevationViewMenuItemActionPerformed(evt);
            }
        });
        windowMenu.add(elevationViewMenuItem);

        databaseMenuItem.setAction(actionMap.get("databaseMenuItemActionPerformed")); // NOI18N
        databaseMenuItem.setText(resourceMap.getString("databaseMenuItem.text")); // NOI18N
        databaseMenuItem.setName("databaseMenuItem"); // NOI18N
        windowMenu.add(databaseMenuItem);

        menuBar.add(windowMenu);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        showPdfMenuItem.setText(resourceMap.getString("showPdfMenuItem.text")); // NOI18N
        showPdfMenuItem.setName("showPdfMenuItem"); // NOI18N
        showPdfMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                showPdfMenuItemActionPerformed(evt);
            }
        });
        helpMenu.add(showPdfMenuItem);

        websiteMenuItem.setText(resourceMap.getString("websiteMenuItem.text")); // NOI18N
        websiteMenuItem.setName("websiteMenuItem"); // NOI18N
        websiteMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                websiteMenuItemActionPerformed(evt);
            }
        });
        helpMenu.add(websiteMenuItem);

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        statusPanel.setName("statusPanel"); // NOI18N

        statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N

        statusMessageLabel.setName("statusMessageLabel"); // NOI18N

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

        progressBar.setName("progressBar"); // NOI18N

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(statusMessageLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 230, Short.MAX_VALUE)
                .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(statusAnimationLabel)
                .addContainerGap())
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(statusMessageLabel)
                    .addComponent(statusAnimationLabel)
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(3, 3, 3))
        );

        mainToolbar.setBorder(null);
        mainToolbar.setRollover(true);
        mainToolbar.setName("mainToolbar"); // NOI18N

        btnConnect.setAction(actionMap.get("clickConnect")); // NOI18N
        btnConnect.setIcon(resourceMap.getIcon("btnConnect.icon")); // NOI18N
        btnConnect.setText(resourceMap.getString("btnConnect.text")); // NOI18N
        btnConnect.setFocusable(false);
        btnConnect.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnConnect.setName("btnConnect"); // NOI18N
        btnConnect.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        mainToolbar.add(btnConnect);

        jSeparator3.setName("jSeparator3"); // NOI18N
        mainToolbar.add(jSeparator3);

        tbSelect.setAction(actionMap.get("onSelect")); // NOI18N
        tbSelect.setIcon(resourceMap.getIcon("tbSelect.icon")); // NOI18N
        tbSelect.setText(resourceMap.getString("tbSelect.text")); // NOI18N
        tbSelect.setFocusable(false);
        tbSelect.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        tbSelect.setName("tbSelect"); // NOI18N
        tbSelect.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        mainToolbar.add(tbSelect);

        tbPan.setAction(actionMap.get("onPan")); // NOI18N
        tbPan.setIcon(resourceMap.getIcon("tbPan.icon")); // NOI18N
        tbPan.setText(resourceMap.getString("tbPan.text")); // NOI18N
        tbPan.setFocusable(false);
        tbPan.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        tbPan.setName("tbPan"); // NOI18N
        tbPan.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        mainToolbar.add(tbPan);

        tbZoom.setAction(actionMap.get("onZoom")); // NOI18N
        tbZoom.setIcon(resourceMap.getIcon("tbZoom.icon")); // NOI18N
        tbZoom.setText(resourceMap.getString("tbZoom.text")); // NOI18N
        tbZoom.setFocusable(false);
        tbZoom.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        tbZoom.setName("tbZoom"); // NOI18N
        tbZoom.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        mainToolbar.add(tbZoom);

        tbZoomArea.setAction(actionMap.get("tbZoomAreaActionPerformed")); // NOI18N
        tbZoomArea.setIcon(resourceMap.getIcon("tbZoomArea.icon")); // NOI18N
        tbZoomArea.setText(resourceMap.getString("tbZoomArea.text")); // NOI18N
        tbZoomArea.setFocusable(false);
        tbZoomArea.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        tbZoomArea.setName("tbZoomArea"); // NOI18N
        tbZoomArea.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        mainToolbar.add(tbZoomArea);

        tbTapZoom.setAction(actionMap.get("zoomTap")); // NOI18N
        tbTapZoom.setIcon(resourceMap.getIcon("tbTapZoom.icon")); // NOI18N
        tbTapZoom.setText(resourceMap.getString("tbTapZoom.text")); // NOI18N
        tbTapZoom.setFocusable(false);
        tbTapZoom.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        tbTapZoom.setName("tbTapZoom"); // NOI18N
        tbTapZoom.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        mainToolbar.add(tbTapZoom);

        jSeparator4.setName("jSeparator4"); // NOI18N
        mainToolbar.add(jSeparator4);

        btnZoomIn.setAction(actionMap.get("clickZoomIn")); // NOI18N
        btnZoomIn.setIcon(resourceMap.getIcon("btnZoomIn.icon")); // NOI18N
        btnZoomIn.setText(resourceMap.getString("btnZoomIn.text")); // NOI18N
        btnZoomIn.setFocusable(false);
        btnZoomIn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnZoomIn.setName("btnZoomIn"); // NOI18N
        btnZoomIn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        mainToolbar.add(btnZoomIn);

        btnZoomOut.setAction(actionMap.get("clickZoomOut")); // NOI18N
        btnZoomOut.setIcon(resourceMap.getIcon("btnZoomOut.icon")); // NOI18N
        btnZoomOut.setText(resourceMap.getString("btnZoomOut.text")); // NOI18N
        btnZoomOut.setFocusable(false);
        btnZoomOut.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnZoomOut.setName("btnZoomOut"); // NOI18N
        btnZoomOut.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        mainToolbar.add(btnZoomOut);

        btnFit.setAction(actionMap.get("clickZoomToFit")); // NOI18N
        btnFit.setIcon(resourceMap.getIcon("btnFit.icon")); // NOI18N
        btnFit.setText(resourceMap.getString("btnFit.text")); // NOI18N
        btnFit.setFocusable(false);
        btnFit.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnFit.setName("btnFit"); // NOI18N
        btnFit.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        mainToolbar.add(btnFit);

        cbZoom.setEditable(true);
        cbZoom.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "10%", "25%", "50%", "75%", "100%", "150%", "200%" }));
        cbZoom.setSelectedIndex(2);
        cbZoom.setAction(actionMap.get("cbZoomActionPerformed")); // NOI18N
        cbZoom.setName("cbZoom"); // NOI18N
        mainToolbar.add(cbZoom);

        jSeparator5.setName("jSeparator5"); // NOI18N
        mainToolbar.add(jSeparator5);

        tbShowAllTrails.setAction(actionMap.get("tbShowAllTrailsActionPerformed")); // NOI18N
        tbShowAllTrails.setIcon(resourceMap.getIcon("tbShowAllTrails.icon")); // NOI18N
        tbShowAllTrails.setText(resourceMap.getString("tbShowAllTrails.text")); // NOI18N
        tbShowAllTrails.setFocusable(false);
        tbShowAllTrails.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        tbShowAllTrails.setName("tbShowAllTrails"); // NOI18N
        tbShowAllTrails.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        mainToolbar.add(tbShowAllTrails);

        tbSelectedTrails.setAction(actionMap.get("tbSelectedTrailsActionPerformed")); // NOI18N
        tbSelectedTrails.setIcon(resourceMap.getIcon("tbSelectedTrails.icon")); // NOI18N
        tbSelectedTrails.setText(resourceMap.getString("tbSelectedTrails.text")); // NOI18N
        tbSelectedTrails.setFocusable(false);
        tbSelectedTrails.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        tbSelectedTrails.setName("tbSelectedTrails"); // NOI18N
        tbSelectedTrails.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        mainToolbar.add(tbSelectedTrails);

        tbDistance.setAction(actionMap.get("tbDistanceActionPerformed")); // NOI18N
        tbDistance.setIcon(resourceMap.getIcon("tbDistance.icon")); // NOI18N
        tbDistance.setText(resourceMap.getString("tbDistance.text")); // NOI18N
        tbDistance.setFocusable(false);
        tbDistance.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        tbDistance.setName("tbDistance"); // NOI18N
        tbDistance.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        mainToolbar.add(tbDistance);

        tbBearingAndDistance.setAction(actionMap.get("tbBearingAndDistanceActionPerformed")); // NOI18N
        tbBearingAndDistance.setIcon(resourceMap.getIcon("tbBearingAndDistance.icon")); // NOI18N
        tbBearingAndDistance.setText(resourceMap.getString("tbBearingAndDistance.text")); // NOI18N
        tbBearingAndDistance.setFocusable(false);
        tbBearingAndDistance.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        tbBearingAndDistance.setName("tbBearingAndDistance"); // NOI18N
        tbBearingAndDistance.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        mainToolbar.add(tbBearingAndDistance);

        jSeparator6.setName("jSeparator6"); // NOI18N
        mainToolbar.add(jSeparator6);

        tbAllFlightPlan.setAction(actionMap.get("tbAllFlightPlanActionPerformed")); // NOI18N
        tbAllFlightPlan.setIcon(resourceMap.getIcon("tbAllFlightPlan.icon")); // NOI18N
        tbAllFlightPlan.setText(resourceMap.getString("tbAllFlightPlan.text")); // NOI18N
        tbAllFlightPlan.setFocusable(false);
        tbAllFlightPlan.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        tbAllFlightPlan.setName("tbAllFlightPlan"); // NOI18N
        tbAllFlightPlan.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        mainToolbar.add(tbAllFlightPlan);

        tbSelectedFlightPlan.setAction(actionMap.get("tbSelectedFlightPlanActionPerformed")); // NOI18N
        tbSelectedFlightPlan.setIcon(resourceMap.getIcon("tbSelectedFlightPlan.icon")); // NOI18N
        tbSelectedFlightPlan.setText(resourceMap.getString("tbSelectedFlightPlan.text")); // NOI18N
        tbSelectedFlightPlan.setFocusable(false);
        tbSelectedFlightPlan.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        tbSelectedFlightPlan.setName("tbSelectedFlightPlan"); // NOI18N
        tbSelectedFlightPlan.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        mainToolbar.add(tbSelectedFlightPlan);

        jSeparator7.setName("jSeparator7"); // NOI18N
        mainToolbar.add(jSeparator7);

        btnRecord.setAction(actionMap.get("btnRecordActionPerformed")); // NOI18N
        btnRecord.setIcon(resourceMap.getIcon("btnRecord.icon")); // NOI18N
        btnRecord.setText(resourceMap.getString("btnRecord.text")); // NOI18N
        btnRecord.setFocusable(false);
        btnRecord.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnRecord.setName("btnRecord"); // NOI18N
        btnRecord.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        mainToolbar.add(btnRecord);

        setComponent(mainPanel);
        setMenuBar(menuBar);
        setStatusBar(statusPanel);
    }// </editor-fold>//GEN-END:initComponents
    //<editor-fold defaultstate="collapsed" desc="Action MenuBar">
    //<editor-fold defaultstate="collapsed" desc="File Menu">
    private void aircraftListMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aircraftListMenuItemActionPerformed
        CloseTopDialog();
        JFileChooser fc = new JFileChooser();
        fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
        FileNameExtensionFilter filter = new FileNameExtensionFilter("PDF files", "pdf");
        fc.setFileFilter(filter);
        int ret = fc.showSaveDialog(null);
        ShowTopDialog();

        if (ret == JFileChooser.APPROVE_OPTION)
        {
            File SelectedFile = fc.getSelectedFile();
            String extension = getExtension(SelectedFile);
            String fileName = SelectedFile.getAbsolutePath();

            if (extension == null || !extension.toLowerCase().equals("pdf"))
            {
                //If file selected without extension or wrong extension
                fileName += ".pdf";
                File NewFile  = new File (fileName);
                SelectedFile = NewFile;
            }

            synchronized(FlightDat)
            {
                PDFWriter pdfWriter = new PDFWriter(SelectedFile.getAbsolutePath(), FlightDat.getFlightList());
            try {
                pdfWriter.createPdf();
            } catch (DocumentException ex) {
                Logger.getLogger(CNSATMSMARTView.class.getName()).log(Level.SEVERE, null, ex);
            } catch (FileNotFoundException ex) {
                Logger.getLogger(CNSATMSMARTView.class.getName()).log(Level.SEVERE, null, ex);
            } catch (MalformedURLException ex) {
                Logger.getLogger(CNSATMSMARTView.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(CNSATMSMARTView.class.getName()).log(Level.SEVERE, null, ex);
            }
            }
        }
    }//GEN-LAST:event_aircraftListMenuItemActionPerformed

    private void copyToClipboardActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_copyToClipboardActionPerformed
        ImageDriver PNGsv = new ImageDriver(ScreenTitle, 200);
        Thread threadPNG = new Thread(PNGsv);
        threadPNG.start();
    }//GEN-LAST:event_copyToClipboardActionPerformed

    private void saveAsJPGMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveAsJPGMenuItemActionPerformed
        CloseTopDialog();
        JFileChooser fc = new JFileChooser();
        fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
        FileNameExtensionFilter filter = new FileNameExtensionFilter("PNG files", "png");
        fc.setFileFilter(filter);
        int ret = fc.showSaveDialog(null);
        ShowTopDialog();

        if (ret == JFileChooser.APPROVE_OPTION)
        {
            File SelectedFile = fc.getSelectedFile();
            String extension = getExtension(SelectedFile);
            String fileName = SelectedFile.getAbsolutePath();

            if (extension == null || !extension.toLowerCase().equals("png"))
            {
                //If file selected without extension or wrong extension
                fileName += ".png";
                File NewFile  = new File (fileName);
                SelectedFile = NewFile;
            }
            ImageDriver PNGsv = new ImageDriver(ScreenTitle, SelectedFile, 200);
            Thread threadPNG = new Thread(PNGsv);
            threadPNG.start();
        }
    }//GEN-LAST:event_saveAsJPGMenuItemActionPerformed

    /**
     * action untuk exitMenuItem
     */
    @Action
    public void exitMenuItemActionPerformed()
    {
        if (FlightTable != null && FlightTable.isVisible()) FlightTable.setAlwaysOnTop(false);
        if (ZoomAreaWindow != null && ZoomAreaWindow.isVisible()) ZoomAreaWindow.setAlwaysOnTop(false);

        int reply = JOptionPane.showConfirmDialog(null, "Do you really want to exit?", "Confirm Exit", JOptionPane.YES_NO_OPTION);
        if (reply == JOptionPane.YES_OPTION){
            if (isConnect){
                try {
                    //Jika masih ada koneksi antara client/receiver dan server/sender, maka ditutup terlebih dahulu
                    Disconnect(true);
                } catch (InterruptedException ex) {
                    Logger.getLogger(CNSATMSMARTView.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IOException ex) {
                    Logger.getLogger(CNSATMSMARTView.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            System.exit(0);
        }else{
            if (FlightTable.isVisible()) FlightTable.setAlwaysOnTop(true);
            if (ZoomAreaWindow.isVisible()) ZoomAreaWindow.setAlwaysOnTop(true);
        }
    }
    //</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="Layers Menu">
    private void mapMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mapMenuItemActionPerformed
        if (mapMenuItem.isSelected()) {
            mapPanel.addMapLayer();
            updateShowAll();
        } else {
            mapPanel.removeMapLayer();
            showAllMenuItem.setSelected(false);
        }
    }//GEN-LAST:event_mapMenuItemActionPerformed

    private void graticuleMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_graticuleMenuItemActionPerformed
        if (graticuleMenuItem.isSelected()) {
            mapPanel.addGratLayer();
            updateShowAll();
        } else {
            mapPanel.removeGratLayer();
            showAllMenuItem.setSelected(false);
        }
    }//GEN-LAST:event_graticuleMenuItemActionPerformed

    private void radarMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radarMenuItemActionPerformed
        if (radarMenuItem.isSelected()) {
            mapPanel.addRadarLayer();
            updateShowAll();
        } else {
            mapPanel.removeRadarLayer();
            showAllMenuItem.setSelected(false);
        }
    }//GEN-LAST:event_radarMenuItemActionPerformed

    private void fixesMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fixesMenuItemActionPerformed
        if (fixesMenuItem.isSelected()) {
            mapPanel.addFixesLayer();
            updateShowAll();
        } else {
            mapPanel.removeFixesLayer();
            showAllMenuItem.setSelected(false);
        }
    }//GEN-LAST:event_fixesMenuItemActionPerformed

    private void airwaysMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_airwaysMenuItemActionPerformed
        if (airwaysMenuItem.isSelected()) {
            mapPanel.addAirwaysLayer();
            updateShowAll();
        } else {
            mapPanel.removeAirwaysLayer();
            showAllMenuItem.setSelected(false);
        }
    }//GEN-LAST:event_airwaysMenuItemActionPerformed

    private void showAllMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showAllMenuItemActionPerformed
        if (!mapMenuItem.isSelected())
            {
                mapMenuItem.setSelected(true);
                mapPanel.addMapLayer();
            }
            if (!radarMenuItem.isSelected())
            {
                radarMenuItem.setSelected(true);
                mapPanel.addRadarLayer();
            }
            if (!graticuleMenuItem.isSelected())
            {
                graticuleMenuItem.setSelected(true);
                mapPanel.addGratLayer();
            }
            if (!fixesMenuItem.isSelected())
            {
                fixesMenuItem.setSelected(true);
                mapPanel.addFixesLayer();
            }
            if (!airwaysMenuItem.isSelected())
            {
                airwaysMenuItem.setSelected(true);
                mapPanel.addAirwaysLayer();
            }
            if (!airportsMenuItem.isSelected())
            {
                airportsMenuItem.setSelected(true);
                mapPanel.addAirportLayer();
            }
            showAllMenuItem.setSelected(true);
    }//GEN-LAST:event_showAllMenuItemActionPerformed

    private void airportsMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_airportsMenuItemActionPerformed
        if (airportsMenuItem.isSelected()) {
            mapPanel.addAirportLayer();
            updateShowAll();
        } else {
            mapPanel.removeAirportLayer();
            showAllMenuItem.setSelected(false);
        }
    }//GEN-LAST:event_airportsMenuItemActionPerformed
    //</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="Options Menu">
    private void radarSettingMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radarSettingMenuItemActionPerformed
        JFrame mainFrame = CNSATMSMARTApp.getApplication().getMainFrame();
        radarSettingsDialog = new radarSettings(mainFrame,true);
        radarSettingsDialog.setLocationRelativeTo(mainFrame);
        CNSATMSMARTApp.getApplication().show(radarSettingsDialog);
    }//GEN-LAST:event_radarSettingMenuItemActionPerformed

    private void connectionMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_connectionMenuItemActionPerformed
        JFrame mainFrame = CNSATMSMARTApp.getApplication().getMainFrame();
        connectionSettingDialog = new connectionSetting(mainFrame,true);
        connectionSettingDialog.setLocationRelativeTo(mainFrame);
        CNSATMSMARTApp.getApplication().show(connectionSettingDialog);
    }//GEN-LAST:event_connectionMenuItemActionPerformed

    private void flightOptionsMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_flightOptionsMenuItemActionPerformed
        JFrame mainFrame = CNSATMSMARTApp.getApplication().getMainFrame();
        flightOptionsDialog = new flightSetting(mainFrame,true);
        flightOptionsDialog.setLocationRelativeTo(mainFrame);
        CNSATMSMARTApp.getApplication().show(flightOptionsDialog);
    }//GEN-LAST:event_flightOptionsMenuItemActionPerformed
    //</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="Window Menu">
    private void flightListMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_flightListMenuItemActionPerformed
        if (isConnect && FlightTable != null){
            FlightTable.setVisible(true);
        }
    }//GEN-LAST:event_flightListMenuItemActionPerformed

    private void elevationViewMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_elevationViewMenuItemActionPerformed
        elevationViewMenuItem.setSelected(! elevationViewMenuItem.isSelected());
        if (elevationViewMenuItem.isSelected()) {
            mapPanel.setBenyengScale(mapPanel.getCurrentScale(), cbZoom);
        } else {
            mapPanel.setUnBenyengScale(mapPanel.getCurrentScale(), cbZoom);
        }
        splitHorPane.setDividerLocation(GlobalEnvVars.screenHeight - (elevationViewMenuItem.isSelected() ? GlobalEnvVars.chartHeight : 0));
    }//GEN-LAST:event_elevationViewMenuItemActionPerformed

    /**
     * action untuk databaseMenuItem
     */
    @Action
    public void databaseMenuItemActionPerformed()
    {
        databaseWindow = new databaseSettings(this);
        databaseWindow.setLocationRelativeTo(this.getFrame());
        databaseWindow.setVisible(true);
    }
    //</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="Help Menu">
    private void showPdfMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showPdfMenuItemActionPerformed
        File filePDF = new File("data/"+GlobalEnvVars.pdf);
            try
            {
                if (filePDF.exists())
                {
                    Process p = Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + filePDF.getAbsolutePath());
                    p.waitFor();
                } else {
                    System.out.println("File is not exists");
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
    }//GEN-LAST:event_showPdfMenuItemActionPerformed

    private void websiteMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_websiteMenuItemActionPerformed
        Desktop desktop = Desktop.getDesktop();
            try {
                URI myNewLocation = new java.net.URI(GlobalEnvVars.websiteBPPT);
                desktop.browse(myNewLocation);
            } catch (Exception e) {
                System.err.println( e.getMessage() );
            }
    }//GEN-LAST:event_websiteMenuItemActionPerformed

    /**
     * action untuk aboutMenuItem
     */
    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = CNSATMSMARTApp.getApplication().getMainFrame();
            aboutBox = new CNSATMSMARTAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        CNSATMSMARTApp.getApplication().show(aboutBox);
    }
    //</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="View Menu">
    private void otherWindowMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_otherWindowMenuItemActionPerformed
        if (otherWindowMenuItem.isSelected()) {
            tabWindowMenuItem.setSelected(false);
            otherWindowMenuItem.setSelected(true);
            isNewWindow = true;
            if (tabPanel.indexOfTab("Zoom Area") != -1) {
                for (int i=0; i < tabPanel.getTabCount(); ++i) {
                    if (tabPanel.getTitleAt(i).equals("Zoom Area"))
                        tabPanel.remove(i);
                }
                ZoomAreaWindow.add(this.mapPanel2);
                ZoomAreaWindow.setVisible(true);
            }
        } else {
            isNewWindow = true;
            otherWindowMenuItem.setSelected(true);
        }
        if (tbZoomArea.isSelected())
            this.mapPanel.setMouseMode(new OverviewMouseMode(this.mapPanel2, this.ZoomAreaWindow, tabPanel, isNewWindow));
    }//GEN-LAST:event_otherWindowMenuItemActionPerformed

    private void tabWindowMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tabWindowMenuItemActionPerformed
        if (tabWindowMenuItem.isSelected()) {
            tabWindowMenuItem.setSelected(true);
            otherWindowMenuItem.setSelected(false);
            isNewWindow = false;
            if (ZoomAreaWindow.isVisible()) {
                if (tabPanel.indexOfTab("Zoom Area") != -1) {
                    tabPanel.remove(1);
                }
                JPanel panel2 = new JPanel();
                panel2.setLayout(new BorderLayout());
                panel2.add(this.mapPanel2, BorderLayout.CENTER);
                panel2.setSize(1000, 600);
                tabPanel.addTab("Zoom Area", panel2);
                ZoomAreaWindow.setVisible(false);
            }
        } else {
            isNewWindow = true;
            if (tabPanel.indexOfTab("Zoom Area") != -1) {
                tabPanel.remove(1);
            }
            otherWindowMenuItem.setSelected(true);
        }
        if (tbZoomArea.isSelected())
            this.mapPanel.setMouseMode(new OverviewMouseMode(this.mapPanel2, this.ZoomAreaWindow, tabPanel, isNewWindow));
    }//GEN-LAST:event_tabWindowMenuItemActionPerformed
    //</editor-fold>
    //</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="Action Toolbar">    
        /**
         * action untuk cbZoom
         */
        @Action
        public void cbZoomActionPerformed()
        {
            String zoomSize = (String)cbZoom.getSelectedItem();
            float persen = 0.5f;
            if (!zoomSize.contains("%"))
            {
                try{
                    persen = Float.parseFloat(zoomSize);
                }catch(NumberFormatException e){
                    zoomSize = "0.5";
                    persen = 0.5f;
                }catch(Exception exp){
                    zoomSize = "0.5";
                    persen = 0.5f;
                }

                if (persen < 0.5f)
                {persen = 0.5f; zoomSize = "0.5";}
                else if (persen > 200f)
                {persen = 200f; zoomSize = "200";}
            }
            else
            {
                String[] temp = zoomSize.split("%");
                if (temp.length != 0)
                {
                    try{
                        persen = Float.parseFloat(temp[0]);
                    }catch(NumberFormatException e){
                        temp[0] = "0.5";
                        persen = 0.5f;
                    }catch(Exception exp){
                        temp[0] = "0.5";
                        persen = 0.5f;
                    }

                    if (persen < 0.5f)
                    {persen = 0.5f; zoomSize = "0.5";}
                    else if (persen > 200f)
                    {persen = 200f; zoomSize = "200";}
                }
                else
                {
                    persen = 0.5f;
                    zoomSize = "0.5";
                }

            }
            changeScale(persen);
        }

        /**
         * action untuk btnConnect
         * @throws IOException
         * @throws InterruptedException
         */
        @Action
        public void clickConnect() throws IOException, InterruptedException
        {
            if (isConnect) //ketika sudah connect mau disconnect
            {
                Disconnect(true);
            }
            else //ketika sudah disconnect mau connect
            {
                Ax21DataList = new Asterix21DataList();
                FlightDat = new FlightList();
                mapPanel.addFlightLayer(this.bottomPanel, this.flightPlanList);
                mapPanel2.addFlightLayer(null,null);

                if (GlobalEnvVars.isUnicast)
                {
                    ct = new ClientThread(GlobalEnvVars.port, GlobalEnvVars.ipServer, Ax21DataList);
                    if (ct.Connect())
                        {threadProcess = new Thread (ct);}
                    else
                    {
                        JOptionPane.showMessageDialog(this.getFrame(),"Can't connect to server","Warning",JOptionPane.YES_NO_OPTION);

                        threadProcess = null;
                    }
                }
                else
                {
                    CMT = new ClientMulticastThread(GlobalEnvVars.ipServer, GlobalEnvVars.port, GlobalEnvVars.BindInterface, Ax21DataList);
                    threadProcess = new Thread (CMT);
                }

                if (threadProcess != null)
                {
                    threadProcess.start();

                    BuffThread = new BufferThread(FlightDat, Ax21DataList);
                    offcheck = new OffCheckThread(FlightDat);
                    FlightTable = new listFlightView();
                    painter = new Painter(FlightDat,this.mapPanel.getFlightLayer(),this.mapPanel2.getFlightLayer(),FlightTable);
                    FPT = new FlightPlanThread(this.flightPlanList);

                    ThreadBuff = new Thread(BuffThread);
                    threadOC = new Thread(offcheck);
                    threadPT = new Thread(painter);
                    threadFPT = new Thread(FPT);
                    
                    ThreadBuff.start();
                    threadPT.start();
                    threadOC.start();
                    threadFPT.start();

                    btnConnect.setText("Disconnect");
                    btnConnect.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cnsatmsmart/resources/disconnect-icon.png")));
                    isConnect = true;

                    this.mapPanel.setMouseMode(new SelectMouseMode());
                    this.tabPanel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                    
                    tbSelect.setSelected(true);
                    tbDistance.setSelected(false);
                    tbSelectedTrails.setSelected(false);
                    tbShowAllTrails.setSelected(false);
                    tbBearingAndDistance.setSelected(false);
                    tbSelectedFlightPlan.setSelected(false);
                    tbAllFlightPlan.setSelected(false);

                    flightListMenuItem.setEnabled(true);
                    elevationViewMenuItem.setEnabled(true);
                    tbDistance.setEnabled(true);
                    tbSelectedTrails.setEnabled(true);
                    tbShowAllTrails.setEnabled(true);
                    btnRecord.setEnabled(true);
                    tbZoomArea.setEnabled(true);
                    tbBearingAndDistance.setEnabled(true);
                    zoomAreaMenu.setEnabled(true);
                    tabWindowMenuItem.setSelected(false);
                    tbAllFlightPlan.setEnabled(true);
                    tbSelectedFlightPlan.setEnabled(true);
                }
            }
        }

        /**
         * action untuk tbSelect - mengubah mouseMode dari peta menjadi SelectMouseMode
         */
        @Action
        public void onSelect()
        {
            this.mapPanel.setMouseMode(new SelectMouseMode());
            if (isConnect)
            {
                if (tbShowAllTrails.isSelected())
                {
                    tbSelectedTrails.setEnabled(false);
                    tbSelectedTrails.setSelected(false);
                }

                if (tbAllFlightPlan.isSelected())
                {
                    tbSelectedFlightPlan.setEnabled(false);
                    tbSelectedFlightPlan.setSelected(false);
                }

                if (tbDistance.isSelected())
                    {tbDistance.setEnabled(true);}
                else if(tbSelectedTrails.isSelected())
                {
                    tbShowAllTrails.setEnabled(false);
                    tbSelectedTrails.setEnabled(true);
                }
                else if(tbSelectedTrails.isSelected())
                {
                    tbAllFlightPlan.setEnabled(true);
                    tbSelectedFlightPlan.setEnabled(false);
                }
                else if(tbBearingAndDistance.isSelected())
                    {tbBearingAndDistance.setEnabled(true);}
                else
                {
                    tbDistance.setEnabled(true);
                    tbSelectedTrails.setEnabled(true);
                    tbShowAllTrails.setEnabled(true);
                    tbBearingAndDistance.setEnabled(true);
                    tbSelectedFlightPlan.setEnabled(true);
                    if (tbShowAllTrails.isSelected())
                        {tbSelectedTrails.setEnabled(false);}
                    if (tbAllFlightPlan.isSelected())
                        {tbSelectedFlightPlan.setEnabled(false);}
                }
            }
            this.tabPanel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
        }

        /**
         * action untuk tbPan - mengubah mouseMode dari peta menjadi PanMouseMode
         */
        @Action
        public void onPan()
        {
            this.mapPanel.setMouseMode(new PanMouseMode());
            this.tabPanel.setCursor(new Cursor(Cursor.MOVE_CURSOR));
            if (isConnect)
            {
                tbShowAllTrails.setEnabled(true);
                tbAllFlightPlan.setEnabled(true);
            }
            tbBearingAndDistance.setEnabled(false);
            tbSelectedTrails.setEnabled(false);
            tbDistance.setEnabled(false);
            tbSelectedFlightPlan.setEnabled(false);
        }

        /**
         * action untuk tbZoom - mengubah mouseMode dari peta menjadi NavMouseMode3
         */
        @Action
        public void onZoom()
        {
            this.mapPanel.setMouseMode(new NavMouseMode3(cbZoom));
            this.tabPanel.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
            if (isConnect)
            {
                tbShowAllTrails.setEnabled(true);
                tbAllFlightPlan.setEnabled(true);
            }
            tbBearingAndDistance.setEnabled(false);
            tbSelectedTrails.setEnabled(false);
            tbDistance.setEnabled(false);
            tbSelectedFlightPlan.setEnabled(false);
        }

        /**
         * action untuk tbTapZoom - mengubah mouseMode dari peta menjadi ZoomMouseMode
         */
        @Action
        public void zoomTap()
        {
            this.mapPanel.setMouseMode(new ZoomMouseMode(cbZoom));
            this.tabPanel.setCursor(new Cursor(Cursor.HAND_CURSOR));
            if (isConnect)
            {
                tbShowAllTrails.setEnabled(true);
                tbAllFlightPlan.setEnabled(true);
            }
            tbBearingAndDistance.setEnabled(false);
            tbSelectedTrails.setEnabled(false);
            tbDistance.setEnabled(false);
            tbSelectedFlightPlan.setEnabled(false);
        }

        /**
         * action untuk tbFit - skala peta menjadi GlobalEnvVars.maxScale
         */
        @Action
        public void clickZoomToFit()
        {
            this.mapPanel.setCenterAndFit();
            cbZoom.setSelectedItem("0.5%");
        }

        /**
         * action untuk btnZoomIn - skala peta mengecil dengan pengurangan sebesar 200000f
         */
        @Action
        public void clickZoomIn()
        {
            float scale = this.mapPanel.getCurrentScale();
            scale -= 200000f;

            this.mapPanel.setCurrentScale(scale,cbZoom);
        }

        /**
         * action untuk btnZoomOut - skala peta membesar dengan penambahannya sebesar 200000f
         */
        @Action
        public void clickZoomOut()
        {
            float scale = this.mapPanel.getCurrentScale();
            scale += 200000f;

            this.mapPanel.setCurrentScale(scale,cbZoom);
        }

        /**
         * action untuk tbDistance - menampilkan jarak antara 2 pesawat
         */
        @Action
        public void tbDistanceActionPerformed()
        {
            if (tbDistance.isSelected())
                {tbBearingAndDistance.setEnabled(false);}
            else
            {
                tbDistance.setFocusable(false);
                tbBearingAndDistance.setEnabled(true);
            }

            if (tbShowAllTrails.isSelected())
                tbSelectedTrails.setEnabled(false);
            else
                tbSelectedTrails.setEnabled(true);

            if (tbAllFlightPlan.isSelected())
                tbSelectedFlightPlan.setEnabled(false);
            else
                tbSelectedFlightPlan.setEnabled(true);

            mapPanel.getFlightLayer().setCalculateDistance(tbDistance.isSelected());
        }

        /**
         * action untuk tbShowAllTrails - menampilkan semua trails dari pesawat yang ada pada peta
         */
        @Action
        public void tbShowAllTrailsActionPerformed()
        {
            if (tbShowAllTrails.isSelected())
            {
                tbSelectedTrails.setEnabled(false);
                mapPanel.getFlightLayer().setTrailMode(mapPanel.getFlightLayer().ALL_TRAIL);
            }
            else
            {
                if (tbSelect.isSelected())
                    if (!tbSelectedFlightPlan.isSelected())
                        tbSelectedTrails.setEnabled(true);
                mapPanel.getFlightLayer().setTrailMode(mapPanel.getFlightLayer().NO_TRAIL);
            }
        }

        /**
         * action untuk tbSelectedTrails -  menampilkan trails dari pesawat yang dipilih
         */
        @Action
        public void tbSelectedTrailsActionPerformed()
        {
            if (tbSelectedTrails.isSelected())
            {
                tbShowAllTrails.setEnabled(false);
                tbDistance.setEnabled(false);
                tbBearingAndDistance.setEnabled(false);
                tbSelectedFlightPlan.setEnabled(false);
                mapPanel.getFlightLayer().setTrailMode(mapPanel.getFlightLayer().SELECTED_TRAIL);
            }
            else
            {
                tbSelectedTrails.setFocusable(false);
                if (!tbDistance.isSelected())
                    tbBearingAndDistance.setEnabled(true);

                if (!tbBearingAndDistance.isSelected())
                    tbDistance.setEnabled(true);

                if (!tbAllFlightPlan.isSelected())
                    tbSelectedFlightPlan.setEnabled(true);

                tbShowAllTrails.setEnabled(true);
                mapPanel.getFlightLayer().setTrailMode(mapPanel.getFlightLayer().NO_TRAIL);
            }
        }

        /**
         * action untuk btnRecord - menyimpan history list pesawat selama merekam dan disimpan sebagai txtfile
         */
        @Action
        public void btnRecordActionPerformed()
        {
            if (isRecord)
            {
                btnRecord.setIcon(new ImageIcon(getClass().getResource("/cnsatmsmart/resources/play-icon.png")));
                btnRecord.setText("Start Record");
                BuffThread.playRec = false;
                isRecord = false;
            }
            else
            {
                CloseTopDialog();
                JFileChooser fc = new JFileChooser();
                fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
                FileNameExtensionFilter filter = new FileNameExtensionFilter(".txt files", "txt");
                fc.setFileFilter(filter);
                int ret = fc.showSaveDialog(null);
                ShowTopDialog();
                
                if (ret == JFileChooser.APPROVE_OPTION)
                {
                    File selectedFile = fc.getSelectedFile();
                    this.BuffThread.setNamaFile(selectedFile);
                    BuffThread.playRec = true;
                    btnRecord.setIcon(new ImageIcon(getClass().getResource("/cnsatmsmart/resources/stop-icon.png")));
                    btnRecord.setText("Stop Record");
                    isRecord = true;
                }

                


            }
        }

        /**
         * action untuk tbZoomArea - mengubah mouseMode dari peta menjadi OverviewMouseMode
         */
        @Action
        public void tbZoomAreaActionPerformed()
        {
            this.mapPanel.setMouseMode(new OverviewMouseMode(this.mapPanel2, this.ZoomAreaWindow, tabPanel, isNewWindow));
            if (!otherWindowMenuItem.isSelected() && !tabWindowMenuItem.isSelected())
                otherWindowMenuItem.setSelected(true);
            this.tabPanel.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
            if (isConnect)
            {
                tbShowAllTrails.setEnabled(true);
                tbAllFlightPlan.setEnabled(true);
            }
            tbBearingAndDistance.setEnabled(false);
            tbSelectedTrails.setEnabled(false);
            tbDistance.setEnabled(false);
            tbSelectedFlightPlan.setEnabled(false);
        }

        /**
         * action untuk tbBearingAndDistance
         */
        @Action
        public void tbBearingAndDistanceActionPerformed()
        {
            if (tbBearingAndDistance.isSelected())
                {tbDistance.setEnabled(false);}
            else
            {
                tbBearingAndDistance.setFocusable(false);
                tbDistance.setEnabled(true);
            }

            if (tbShowAllTrails.isSelected())
                tbSelectedTrails.setEnabled(false);
            else
                tbSelectedTrails.setEnabled(true);

            if (tbAllFlightPlan.isSelected())
                tbSelectedFlightPlan.setEnabled(false);
            else
                tbSelectedFlightPlan.setEnabled(true);

            this.mapPanel.getFlightLayer().setBearingDistance(tbBearingAndDistance.isSelected());
        }

        /**
         * action untuk tbAllFlightPlan - menampilkan semua flightPlan
         */
        @Action
        public void tbAllFlightPlanActionPerformed()
        {
            if (tbAllFlightPlan.isSelected())
            {
                tbSelectedFlightPlan.setEnabled(false);
                this.mapPanel.getFlightLayer().setFlightPlanMode(mapPanel.getFlightLayer().ALL_FLIGHTPLAN);
            }
            else
            {
                if (tbSelect.isSelected())
                    if (!tbSelectedTrails.isSelected())
                        tbSelectedFlightPlan.setEnabled(true);
                this.mapPanel.getFlightLayer().setFlightPlanMode(mapPanel.getFlightLayer().NO_FLIGHTPLAN);
            }
        }

        /**
         * action untuk tbSelectedFlightPlan - menampilkan flightplan dari pesawat yang dipilih
         */
        @Action
        public void tbSelectedFlightPlanActionPerformed()
        {
            if (tbSelectedFlightPlan.isSelected())
            {
                tbAllFlightPlan.setEnabled(false);
                tbDistance.setEnabled(false);
                tbBearingAndDistance.setEnabled(false);
                tbSelectedTrails.setEnabled(false);
                this.mapPanel.getFlightLayer().setFlightPlanMode(mapPanel.getFlightLayer().SELECTED_FLIGHTPLAN);
            }
            else
            {
                tbSelectedFlightPlan.setFocusable(false);
                if (!tbDistance.isSelected())
                        tbBearingAndDistance.setEnabled(true);

                if (!tbBearingAndDistance.isSelected())
                        tbDistance.setEnabled(true);

                if (!tbShowAllTrails.isSelected())
                        tbSelectedTrails.setEnabled(true);

                tbAllFlightPlan.setEnabled(true);
                this.mapPanel.getFlightLayer().setFlightPlanMode(mapPanel.getFlightLayer().NO_FLIGHTPLAN);
            }
        }
        //</editor-fold>

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem aircraftListMenuItem;
    private javax.swing.JCheckBoxMenuItem airportsMenuItem;
    private javax.swing.JCheckBoxMenuItem airwaysMenuItem;
    private javax.swing.JButton btnConnect;
    private javax.swing.JButton btnFit;
    private javax.swing.JButton btnRecord;
    private javax.swing.JButton btnZoomIn;
    private javax.swing.JButton btnZoomOut;
    private javax.swing.JComboBox cbZoom;
    private javax.swing.JMenuItem connectionMenuItem;
    private javax.swing.JMenuItem copyToClipboard;
    private javax.swing.JMenuItem databaseMenuItem;
    private javax.swing.JMenuItem elevationViewMenuItem;
    private javax.swing.JCheckBoxMenuItem fixesMenuItem;
    private javax.swing.JMenuItem flightListMenuItem;
    private javax.swing.JMenuItem flightOptionsMenuItem;
    private javax.swing.JCheckBoxMenuItem graticuleMenuItem;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JPopupMenu.Separator jSeparator2;
    private javax.swing.JToolBar.Separator jSeparator3;
    private javax.swing.JToolBar.Separator jSeparator4;
    private javax.swing.JToolBar.Separator jSeparator5;
    private javax.swing.JToolBar.Separator jSeparator6;
    private javax.swing.JToolBar.Separator jSeparator7;
    private javax.swing.JMenu layersMenu;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JToolBar mainToolbar;
    private javax.swing.JCheckBoxMenuItem mapMenuItem;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JMenu optionsMenu;
    private javax.swing.JRadioButtonMenuItem otherWindowMenuItem;
    private javax.swing.JMenu printMenu;
    private javax.swing.JProgressBar progressBar;
    private javax.swing.JCheckBoxMenuItem radarMenuItem;
    private javax.swing.JMenuItem radarSettingMenuItem;
    private javax.swing.JMenuItem saveAsJPGMenuItem;
    private javax.swing.JCheckBoxMenuItem showAllMenuItem;
    private javax.swing.JMenuItem showPdfMenuItem;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    private javax.swing.JPanel statusPanel;
    private javax.swing.JRadioButtonMenuItem tabWindowMenuItem;
    private javax.swing.JToggleButton tbAllFlightPlan;
    private javax.swing.JToggleButton tbBearingAndDistance;
    private javax.swing.JToggleButton tbDistance;
    private javax.swing.JToggleButton tbPan;
    private javax.swing.JToggleButton tbSelect;
    private javax.swing.JToggleButton tbSelectedFlightPlan;
    private javax.swing.JToggleButton tbSelectedTrails;
    private javax.swing.JToggleButton tbShowAllTrails;
    private javax.swing.JToggleButton tbTapZoom;
    private javax.swing.JToggleButton tbZoom;
    private javax.swing.JToggleButton tbZoomArea;
    private javax.swing.JMenu viewMenu;
    private javax.swing.JMenuItem websiteMenuItem;
    private javax.swing.JMenu windowMenu;
    private javax.swing.JMenu zoomAreaMenu;
    // End of variables declaration//GEN-END:variables

    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;

    private JDialog aboutBox;
    private JPanel sidePanel = new JPanel();
    private JPanel bottomPanel = new JPanel();
    private ButtonGroup buttonGroup;
    private JDialog radarSettingsDialog;
    private JDialog connectionSettingDialog;
    private JDialog flightOptionsDialog;
    private JDialog databaseWindow;
}
